from typing import Dict, Any
from .provider_http import HttpQwenProvider
from .provider_local import LocalQwenProvider
from .provider_hybridflow import HybridFlowQwenProvider
from intelli_port.commons.config import load_settings


class QwenInferencer:
    def __init__(self, provider: str, endpoint: str = "", edge_path: str = ""):
        self.provider = provider
        if provider == "http":
            self.backend = HttpQwenProvider(endpoint)
        elif provider == "hybridflow":
            self.backend = HybridFlowQwenProvider()
        else:
            self.backend = LocalQwenProvider(edge_path)

    def infer_short_text(self, text: str, lang: str = "zh") -> Dict[str, Any]:
        return self.backend.infer(text=text, lang=lang)


def create_qwen_inferencer() -> QwenInferencer:
    s = load_settings()
    return QwenInferencer(s.qwen_provider, s.qwen_http_endpoint, s.qwen_edge_path)